package com.wsoft.form.controller;

import com.wsoft.form.entity.WfFormVirtualColumnEntity;
import com.wsoft.form.query.virtual.column.VirtualColumnInsertQuery;
import com.wsoft.form.query.virtual.column.VirtualColumnListQuery;
import com.wsoft.form.query.virtual.column.VirtualColumnUpdateQuery;
import com.wsoft.form.service.IWfFormVirtualColumnService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 自定义表单-虚拟字段表 前端控制器
 * </p>
 *
 * @author Z001
 * @since 2024年08月29日 09:11:06
 */
@RestController
@Tag(name = "虚拟字段")
@RequestMapping("/wf/virtual")
public class WfFormVirtualColumnController {

    @Resource
    private IWfFormVirtualColumnService virtualColumnService;

    @Operation(summary = "新增虚拟字段", description = "新增虚拟字段")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid VirtualColumnInsertQuery query) {
        boolean b = virtualColumnService.insertVirtualColumn(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改虚拟字段", description = "修改虚拟字段")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid VirtualColumnUpdateQuery query) {
        boolean b = virtualColumnService.updateVirtualColumn(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "查询表中所有虚拟字段", description = "查询表中所有虚拟字段")
    @GetMapping("/list")
    public ResponseResult list(@RequestParam("id") Long id) {
        List<WfFormVirtualColumnEntity> list = virtualColumnService.listVirtualColumn(id);
        return ResponseResult.success(list);
    }

    @Operation(summary = "获取虚拟字段表和字段列表(用于修改)", description = "获取虚拟字段表和字段列表(用于修改)")
    @ApiResponse(responseCode = "200", description = "OK")
    @GetMapping("/get")
    public ResponseResult virtualColumnInfo(@RequestParam("id") Long virtualColumnId) {
        return ResponseResult.success(virtualColumnService.virtualColumnInfo(virtualColumnId));
    }

    @Operation(summary = "删除虚拟字段", description = "删除虚拟字段")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = virtualColumnService.delVirtualColumn(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

}
